#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Time    : 2020/12/1 16:16
# @Author  : Lihuan
# @Site    : 
# @File    : my_cache.py
# @Software: PyCharm

class Cache:
    c = {}

    def __setitem__(self, key, value):
        self.c[key] = value

    def __getitem__(self, key):
        return self.c[key]

    def __delitem__(self, key):
        if key in self.c:
            del self.c[key]
            return 1
        return 0

    def get(self, key):
        return self.c[key]

    def set(self, key, value):
        self.c[key] = value

    def delete(self, key):
        if key in self.c:
            del self.c[key]
            return 1
        return 0

    def exist(self, key):
        return key in self.c

    def clear(self):
        length = len(self.c)
        self.c.clear()
        return length

    def sets(self, **kwarg):
        for key, value in kwarg.items():
            self.c[key] = value
